package com.irisking.server.client;

import io.netty.channel.Channel;
import java.net.InetSocketAddress;

/**
 * 会话封装类
 * @author -weiz-
 *
 */
public class DeviceClient {
	private String clientIP;

	private  int clientPort;

	private int beatCount;

	public  String getKey() {
		return clientIP + ":" + clientPort;
	}

	/**
	 * 实际会话对象
	 */
	private Channel channel;

	public DeviceClient(Channel channel) {
		this.channel = channel;
		InetSocketAddress socket = (InetSocketAddress) channel.remoteAddress();
		this.clientPort = socket.getPort();
		this.clientIP = socket.getAddress().getHostAddress();
	}

	public void write(Object message) {
		channel.writeAndFlush(message);
	}

	public boolean isConnected() {
		return channel.isActive();
	}

	public void close() {
		channel.close();
	}


	public String getClientIP() {
		return clientIP;
	}

	public void setClientIP(String clientIP) {
		this.clientIP = clientIP;
	}

	public int getClientPort() {
		return clientPort;
	}

	public void setClientPort(int clientPort) {
		clientPort = clientPort;
	}

	public int getBeatCount() {
		return beatCount;
	}

	public void setBeatCount(int beatCount) {
		this.beatCount = beatCount;
	}
}
